package com.study.rocketmq;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl;
import org.apache.rocketmq.client.impl.producer.TopicPublishInfo;
import org.apache.rocketmq.client.producer.DefaultMQProducer;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * TODO
 *
 * @author wanghuilong
 * @version 1.0
 * @date 2021/3/31 3:56 下午
 */
@Slf4j
public class Test {

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException
            , IllegalAccessException, MQClientException {
        DefaultMQProducer producer = new DefaultMQProducer("test_group1");
        // Specify name server addresses.
        producer.setNamesrvAddr("10.211.55.3:9876");
        producer.setSendMsgTimeout(10000);
        producer.start();
        try {
            Class clazz = DefaultMQProducerImpl.class;
            Method tryToFindTopicPublishInfo = clazz.getDeclaredMethod("tryToFindTopicPublishInfo", String.class);
            tryToFindTopicPublishInfo.setAccessible(true);
            TopicPublishInfo topicPublishInfo =
                    (TopicPublishInfo) tryToFindTopicPublishInfo.invoke(producer.getDefaultMQProducerImpl(), "TopicTest");
            if (topicPublishInfo.ok()) {
                log.info("OK topicPublishInfo:{}", topicPublishInfo);
            } else {
                log.info("NOT OK topicPublishInfo:{}", topicPublishInfo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        producer.shutdown();
    }

}
